package com.dingpeikeji.quickdeer.mobile.web;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.utils.DateUtils;
import com.dingpeikeji.quickdeer.core.modules.activity.entity.ActivityInfo;
import com.dingpeikeji.quickdeer.core.modules.activity.service.TActivityService;
import com.dingpeikeji.quickdeer.core.modules.cupons.entity.CuponsInfo;
import com.dingpeikeji.quickdeer.core.modules.cupons.service.TCuponsService;
import com.dingpeikeji.quickdeer.core.modules.distribution.entity.DistributionInfo;
import com.dingpeikeji.quickdeer.core.modules.distribution.service.TDistributionService;
import com.dingpeikeji.quickdeer.core.modules.line.entity.TLine;
import com.dingpeikeji.quickdeer.core.modules.orders.entity.TOrders;
import com.dingpeikeji.quickdeer.core.modules.orders.service.TOrdersService;
import com.dingpeikeji.quickdeer.core.modules.sys.entity.SysAds;
import com.dingpeikeji.quickdeer.core.modules.sys.entity.User;
import com.dingpeikeji.quickdeer.core.modules.sys.service.SysAdsService;
import com.dingpeikeji.quickdeer.core.modules.sys.service.SystemService;
import com.dingpeikeji.quickdeer.core.modules.trip.entity.MealsInfo;
import com.dingpeikeji.quickdeer.mobile.entity.CitySceneryInfo;
import com.dingpeikeji.quickdeer.mobile.entity.DestinationInfo;
import com.dingpeikeji.quickdeer.mobile.entity.ExtractInfo;
import com.dingpeikeji.quickdeer.mobile.entity.HotelStandardInfo;
import com.dingpeikeji.quickdeer.mobile.entity.OrderInfo;
import com.dingpeikeji.quickdeer.mobile.entity.StayStandardInfo;
import com.dingpeikeji.quickdeer.mobile.entity.ThemeInfo;
import com.dingpeikeji.quickdeer.mobile.entity.TrafficInfo;
import com.dingpeikeji.quickdeer.mobile.entity.TransportWayInfo;
import com.dingpeikeji.quickdeer.mobile.entity.TripCounselorInfo;
import com.dingpeikeji.quickdeer.mobile.service.CitySceneryService;
import com.dingpeikeji.quickdeer.mobile.service.DestinationService;
import com.dingpeikeji.quickdeer.mobile.service.ExtractService;
import com.dingpeikeji.quickdeer.mobile.service.HotelStandardService;
import com.dingpeikeji.quickdeer.mobile.service.MobileAirRentService;
import com.dingpeikeji.quickdeer.mobile.service.MobileDayRentService;
import com.dingpeikeji.quickdeer.mobile.service.MobileDemandService;
import com.dingpeikeji.quickdeer.mobile.service.MobileOrderService;
import com.dingpeikeji.quickdeer.mobile.service.MobileRcptService;
import com.dingpeikeji.quickdeer.mobile.service.MobileUserService;
import com.dingpeikeji.quickdeer.mobile.service.OrderService;
import com.dingpeikeji.quickdeer.mobile.service.StayStandardService;
import com.dingpeikeji.quickdeer.mobile.service.ThemeService;
import com.dingpeikeji.quickdeer.mobile.service.TrafficService;
import com.dingpeikeji.quickdeer.mobile.service.TransportWayService;
import com.dingpeikeji.quickdeer.mobile.service.TravelProductService;
import com.dingpeikeji.quickdeer.mobile.service.TripCounselorService;
import com.dingpeikeji.quickdeer.modules.rcpt.entity.TUsersRcpt;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TCargotype;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TCargotypeForsale;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TDemands;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TRentgroup;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TRentproduct;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.ShareProductService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.TRentgroupService;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.TRentproductService;
import com.dingpeikeji.quickdeer.modules.sms.service.CkeckTelephoneService;
import com.dingpeikeji.quickdeer.modules.utils.ValidateTool;
import com.dingpeikeji.quickdeer.utils.BackResult;
import com.dingpeikeji.quickdeer.utils.CookieUtils;
import com.dingpeikeji.quickdeer.utils.JsonUtils;
import com.google.common.collect.Lists;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("${frontPath}/mobile")
public class MobileJsonController {
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	Map<String, Object> map;

	@Autowired
	private ThemeService themeService;
	@Autowired
	private HotelStandardService hotelStandardService;
	@Autowired
	private TransportWayService transportWayService;
	@Autowired
	private TActivityService tActivityService;
	@Autowired
	private StayStandardService stayStandardService;
	@Autowired
	private TrafficService trafficService;
	@Autowired
	private SysAdsService sysAdsService;
	@Autowired
	private CitySceneryService citySceneryService;
	@Autowired
	private TripCounselorService tripCounselorService;
	@Autowired
	private DestinationService destinationService;
	@Autowired
	private ExtractService extractService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private TDistributionService distributionService;
	@Autowired
	private TCuponsService tCuponsService;
	@Autowired
	private ShareProductService shareProductService;
	@Autowired
	private TOrdersService tOrdersService;
	public static final String FRONT_USER = "frontUser";
	@Autowired
	private MobileUserService mobileUserService;
	@Autowired
	private TravelProductService travelProductService;
	@Autowired
	private MobileDemandService mobileDemandService;
	@Autowired
	private MobileDayRentService mobileDayRentService;
	@Autowired
	private MobileAirRentService mobileAirRentService;
	@Autowired
	private MobileOrderService mobileOrderService;
	@Autowired
	private MobileRcptService mobileRcptService;
	@Autowired
	private TDistributionService tDistributionService;
	@Autowired
	private TRentproductService tRentproductService;
	@Autowired
	private TRentgroupService tRentgroupService;
	@Autowired
	private SystemService systemService;
	
	@RequestMapping(value = "getBannerImage", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getBannerImage() {
		BackResult result = mobileUserService.getBannerImage();
		return result;
	}
	@RequestMapping(value = "readText", method = RequestMethod.GET)
	public void readText(HttpServletResponse response) throws Exception {
		mobileUserService.readText(response);
	}
	@RequestMapping(value = "getUserInfo", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getUserInfoById(String userid) {
		BackResult result = mobileUserService.getUserInfoById(userid);
		return result;
	}
	@RequestMapping("getProductById")
	public void getProductById(String rentid,HttpServletResponse response,String rentday) throws Exception {
		TRentproduct tRentproduct = tRentproductService.get(rentid);
		TRentgroup tRentgroup = tRentgroupService.get(tRentproduct.getRentgrpid());
		if (tRentgroup.getProductname().contains("跨市")) {
			response.getWriter().println(1);
		}else if (tRentgroup.getProductname().contains("市内")) {
			if ("0".equals(rentday)) {//市内0.5天
				response.getWriter().println(3);
				return;
			}
			response.getWriter().println(2);
		}
	}
	@RequestMapping(value = "login", method = RequestMethod.POST)
	@ResponseBody
	public BackResult doLogin(HttpServletRequest request, HttpServletResponse response, String username,
			String password) throws Exception {
		BackResult result = mobileUserService.login(username, password);
		// 登录成功后写cookie
		if (result.getCode().equals("200")) {
			// 把token写入cookie,cookie的有效期是关闭浏览器就失效
			CookieUtils.setCookie(request, response, "TOKEN_KEY", result.getData().toString());
		}
		return result;
	}

	@RequestMapping(value = "/token/{token}", method = RequestMethod.GET)
	@ResponseBody
	public BackResult getUserByToken(@PathVariable String token) {
		BackResult result = mobileUserService.getUserByToken(token);
		return result;
	}

	@RequestMapping(value = "/logout/{token}", method = RequestMethod.GET)
	@ResponseBody
	public BackResult logoutByToken(@PathVariable String token, String callback) {
		BackResult result = mobileUserService.logoutByToken(token);
		return result;
	}

	@RequestMapping(value = "/modifyNickName")
	@ResponseBody
	public BackResult modifyNickName(String token, HttpServletRequest request) {
		BackResult result = mobileUserService.modifyNickName(token, request);
		return result;
	}

	@RequestMapping(value = "/modifyUserImage")
	@ResponseBody
	public BackResult modifyUserImage(HttpServletRequest request, HttpServletResponse response, String userid,
			String token) throws Exception {
		BackResult message = mobileUserService.modifyUserImage(request, response, userid, token);
		return message;
	}

	@RequestMapping(value = "/modifyPwd")
	@ResponseBody
	public BackResult modifyPwd(String token, String oldPassword, String newPassword, String repeatPassword) {
		BackResult result = mobileUserService.modifyPwd(token, oldPassword, newPassword, repeatPassword);
		return result;
	}

	@RequestMapping("/check/{param}/{type}")
	@ResponseBody
	public BackResult checkUserData(@PathVariable String param, @PathVariable Integer type) {
		BackResult result = mobileUserService.checkData(param, type);
		return result;
	}

	@RequestMapping("/sendMes/{phone}/{type}")
	@ResponseBody
	public BackResult sendMes(@PathVariable String phone, @PathVariable Integer type, HttpServletRequest request) {
		BackResult result = mobileUserService.sendMes(phone, type, request);
		return result;
	}

	@RequestMapping(value = "register", method = RequestMethod.POST)
	@ResponseBody
	public BackResult register(User user, String validateCode, String officeName, HttpServletRequest request) {
		BackResult result = mobileUserService.register(user, validateCode, officeName, request);
		return result;
	}

	@RequestMapping(value = "forgetPwd", method = RequestMethod.POST)
	@ResponseBody
	public BackResult forgetPwd(String mobile, String password1, String password2, String validateCode,
			HttpServletRequest request) {
		BackResult result = mobileUserService.forgetPwd(mobile, password1, password2, validateCode, request);
		return result;
	}

	@RequestMapping(value = "mobileQqcallBack", method = RequestMethod.POST)
	@ResponseBody
	public BackResult mobileQqcallBack(String openid) {
		BackResult result = mobileUserService.mobileQqcallBack(openid);
		return result;
	}

	@RequestMapping(value = "mobileBindQq", method = RequestMethod.POST)
	@ResponseBody
	public BackResult mobileBindQq(HttpServletRequest request, String validateCode) throws Exception {
		BackResult result = mobileUserService.mobileBindQq(request, validateCode);
		return result;
	}

	@RequestMapping(value = "mobileWxcallBack", method = RequestMethod.POST)
	@ResponseBody
	public BackResult mobileWxcallBack(String unionid) throws IOException, ServletException {
		BackResult result = mobileUserService.mobileWxcallBack(unionid);
		return result;
	}

	@RequestMapping(value = "mobileBindWx", method = RequestMethod.POST)
	@ResponseBody
	public BackResult mobileBindWx(HttpServletRequest request, String validateCode) throws Exception {
		BackResult result = mobileUserService.mobileBindWx(request, validateCode);
		return result;
	}

	@RequestMapping(value = "/getSiteList/spottypes/{spottypes}", method = RequestMethod.GET)
	@ResponseBody
	public BackResult getSiteList(@PathVariable String spottypes) {
		if ("0".equals(spottypes) || "9".equals(spottypes)) {
			BackResult result = mobileUserService.getSiteList(spottypes);
			return result;
		}
		return BackResult.build("500", "参数错误");
	}

	@RequestMapping(value = "getSiteidByName", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getSiteidByName(String cityname) {
		BackResult result = mobileUserService.getSiteidByName(cityname);
		return result;
	}

	@RequestMapping(value = "/getTravelList", method = RequestMethod.POST)
	@ResponseBody
	public BackResult travelList(TRentproduct tRentproduct, TRentgroup tRentgroup, HttpServletRequest request,
			HttpServletResponse response, String pageNo, String pageSize, Model model, String destination,
			String estday) throws Exception {
		BackResult result = travelProductService.travelList(tRentproduct, tRentgroup, request, response, pageNo,
				pageSize, model, destination, estday);
		return result;
	}

	@RequestMapping(value = "/getHotTravelList", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getHotTravelList(TRentproduct tRentproduct, TRentgroup tRentgroup, HttpServletRequest request,
			Model model,HttpServletResponse response) throws Exception {
		BackResult result = travelProductService.getHotTravelList(tRentproduct, tRentgroup,response, request, model);
		return result;
	}

	@RequestMapping(value = "/getCityByIp")
	@ResponseBody
	public BackResult getCityByIp(HttpServletRequest request) throws Exception {
		BackResult result = travelProductService.getCityByIp(request);
		return result;
	}

	@RequestMapping(value = "/getTravelDetail")
	@ResponseBody
	public BackResult getTravelDetail(TLine tLine) throws Exception {
		BackResult result = travelProductService.travelDetails(tLine);
		return result;
	}

	@RequestMapping(value = "/travelBook")
	@ResponseBody
	public BackResult travelBook(TRentproduct tRentproduct, String pageNo, String pageSize, Model model,
			TCargotype tCargotype, TRentgroup tRentgroup, TLine tLine, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		BackResult result = travelProductService.travelBook(tRentproduct, pageNo, pageSize, model, tCargotype,
				tRentgroup, tLine, request, response);
		return result;
	}

	@RequestMapping(value = "/genOrderDetails")
	@ResponseBody
	public BackResult orderDetails(TRentproduct tRentproduct, Model model, HttpServletRequest request)
			throws Exception {
		BackResult result = travelProductService.genOrderDetails(tRentproduct, model, request);
		return result;
	}

	@RequestMapping(value = "/getOutFee")
	public void getOutFee(TRentproduct tRentproduct, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		travelProductService.getOutFee(tRentproduct, request, response);
	}

	@RequestMapping(value = "/getCurrentPrice")
	@ResponseBody
	public BackResult getCurrentPrice(TRentproduct tRentproduct, HttpServletRequest request) throws Exception {
		BackResult result = travelProductService.getCurrentPrice(tRentproduct, request);
		return result;
	}

	@RequestMapping(value = "/genOrderData")
	@ResponseBody
	public BackResult genOrderData(TOrders orders, Model model, TRentgroup tRentgroup, HttpServletRequest request,
			CuponsInfo cuponsInfo) throws Exception {
		BackResult result = travelProductService.genOrderData(cuponsInfo, orders, model, tRentgroup, request);
		return result;
	}

	@RequestMapping(value = "/orderPay")
	@ResponseBody
	public BackResult pay(TOrders orders) throws Exception {
		BackResult result = travelProductService.pay(orders);
		return result;
	}

	@RequestMapping(value = "/getCargotypeList")
	@ResponseBody
	public BackResult getCargotypeList() throws Exception {
		BackResult result = mobileDemandService.getCargotypeList();
		return result;
	}

	@RequestMapping(value = "/saveDemand", method = RequestMethod.POST)
	@ResponseBody
	public BackResult saveDemand(TDemands tDemands, HttpServletRequest request) {
		BackResult result = mobileDemandService.saveDemand(tDemands, request);
		return result;
	}

	@RequestMapping(value = "/demandList", method = RequestMethod.POST)
	@ResponseBody
	public BackResult demandList(TDemands tDemands, HttpServletRequest request, HttpServletResponse response) {
		BackResult result = mobileDemandService.demandList(tDemands, request, response);
		return result;
	}

	@RequestMapping(value = "/demandDetail")
	@ResponseBody
	public BackResult demandDetail(TDemands tDemands) {
		BackResult result = mobileDemandService.demandDetail(tDemands);
		return result;
	}

	@RequestMapping(value = "/submitDemandOrder", method = RequestMethod.POST)
	@ResponseBody
	public BackResult submitDemandOrder(CuponsInfo cuponsInfo, TOrders orders, TDemands tDemands, Integer reactid,
			Model model, HttpServletRequest request, String userid) throws ParseException {
		BackResult result = mobileDemandService.submitDemandOrder(cuponsInfo, orders, tDemands, reactid, model, request,
				userid);
		return result;
	}

	@RequestMapping(value = "cancelDemand")
	@ResponseBody
	public BackResult cancelDemand(TDemands tDemands) {
		BackResult result = mobileDemandService.cancel(tDemands);
		return result;
	}

	@RequestMapping(value = "deleteDemand")
	@ResponseBody
	public BackResult deleteDemand(TDemands tDemands) {
		BackResult result = mobileDemandService.deleteDemand(tDemands);
		return result;
	}

	@RequestMapping(value = "/getDayRentList", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getDayRentList(TRentproduct tRentproduct, HttpServletRequest request,
			HttpServletResponse response, Model model, TCargotype tCargotype, String pageNo, String pageSize)
			throws Exception {
		BackResult result = mobileDayRentService.getDayRentList(tRentproduct, request, response, model, tCargotype,
				pageNo, pageSize);
		return result;
	}

	@RequestMapping(value = "/genDayRentOrderData", method = RequestMethod.POST)
	@ResponseBody
	public BackResult genOrderDetails(TRentproduct tRentproduct, Model model, HttpServletRequest request)
			throws Exception {
		BackResult result = mobileDayRentService.genDayRentOrderData(tRentproduct, model, request);
		return result;
	}

	@RequestMapping(value = "/submitDayRentOrder", method = RequestMethod.POST)
	@ResponseBody
	public BackResult submitDayRentOrder(CuponsInfo cuponsInfo, TOrders orders, Model model, HttpServletRequest request)
			throws Exception {
		BackResult result = mobileDayRentService.submitDayRentOrder(cuponsInfo, orders, model, request);
		return result;
	}

	@RequestMapping(value = "/getAirList", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getAirList(CuponsInfo cuponsInfo, TRentproduct tRentproduct, HttpServletRequest request,
			HttpServletResponse response, Model model, TCargotypeForsale cargotypeForsale) throws Exception {
		BackResult result = mobileAirRentService.getAirList(cuponsInfo, tRentproduct, request, response, model,
				cargotypeForsale);
		return result;
	}

	@RequestMapping(value = "/submitAirRentOrder", method = RequestMethod.POST)
	@ResponseBody
	public BackResult submitAirRentOrder(CuponsInfo cuponsInfo, TOrders orders, Model model, HttpServletRequest request,
			TRentproduct tRentproduct) throws Exception {
		BackResult result = mobileAirRentService.submitAirRentOrder(cuponsInfo, orders, model, request, tRentproduct);
		return result;
	}

	@RequestMapping(value = "/getOrderList", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getOrderList(TOrders orders, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BackResult result = mobileOrderService.getOrderList(orders, request, response);
		return result;
	}

	@RequestMapping(value = "/getOrderDetail", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getOrderDetail(TOrders orders,HttpServletRequest request) {
		BackResult result = mobileOrderService.getOrderDetail(orders,request);
		return result;
	}

	@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
	@ResponseBody
	public BackResult cancelOrder(TOrders orders) {
		BackResult result = mobileOrderService.cancelOrder(orders);
		return result;
	}

	@RequestMapping(value = "/delOrder", method = RequestMethod.POST)
	@ResponseBody
	public BackResult delOrder(String orderid) {
		BackResult result = mobileOrderService.del(orderid);
		return result;
	}

	@RequestMapping(value = "/toBackMoneyPage", method = RequestMethod.POST)
	@ResponseBody
	public BackResult toBackMoneyPage(HttpServletRequest request) throws Exception {
		BackResult result = mobileOrderService.toBackMoneyPage(request);
		return result;
	}

	@RequestMapping(value = "/backMoney", method = RequestMethod.POST)
	@ResponseBody
	public BackResult backMoney(TOrders orders, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		BackResult result = mobileOrderService.backMoney(orders, request, response);
		return result;
	}

	@RequestMapping(value = "/rcptHistory", method = RequestMethod.POST)
	@ResponseBody
	public BackResult rcptHistory(TUsersRcpt tUsersRcpt, String userid, HttpServletRequest request,
			HttpServletResponse response, String pageNo, String pageSize) throws Exception {
		BackResult result = mobileRcptService.rcptHistory(tUsersRcpt, userid, request, response, pageNo, pageSize);
		return result;
	}

	@RequestMapping(value = "/userRcptInfo", method = RequestMethod.POST)
	@ResponseBody
	public BackResult userRcptInfo(TUsersRcpt tUsersRcpt, String userid) throws Exception {
		BackResult result = mobileRcptService.userRcptInfo(tUsersRcpt, userid);
		return result;
	}

	@RequestMapping(value = "/saveUserRcptInfo", method = RequestMethod.POST)
	@ResponseBody
	public BackResult saveUserRcptInfo(TUsersRcpt tUsersRcpt, String userid) throws Exception {
		BackResult result = mobileRcptService.saveUserRcptInfo(tUsersRcpt, userid);
		return result;
	}

	@RequestMapping(value = "/rcptOrders", method = RequestMethod.POST)
	@ResponseBody
	public BackResult rcptOrders(String userid, String pageNo, String pageSize, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		BackResult result = mobileRcptService.rcptOrders(userid, pageNo, pageSize, request, response);
		return result;
	}

	@RequestMapping(value = "/saveRcpt", method = RequestMethod.POST)
	@ResponseBody
	public BackResult saveRcpt(TUsersRcpt tUsersRcpt, String rcptIds, String userid, String outkmsfee,
			String outtimefee, String dirverfee) {
		BackResult result = mobileRcptService.saveRcpt(tUsersRcpt, rcptIds, userid, outkmsfee, outtimefee, dirverfee);
		return result;
	}

	/**
	 * 支付宝支付APP参数
	 * 
	 * @param tradeNo
	 * @param subject
	 * @param body
	 * @return
	 */
	@RequestMapping(value = "/getAliPayParams", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getPayParams(String tradeNo, String userid) {
		BackResult result = mobileRcptService.getAliPayParams(tradeNo, userid);
		return result;
	}

	/**
	 * 微信支付APP参数
	 * 
	 * @param tradeNo
	 * @param subject
	 * @param body
	 * @return
	 */
	@RequestMapping(value = "/getWxPayParams", method = RequestMethod.POST)
	@ResponseBody
	public BackResult getWxPayParams(String tradeNo, String body, String userid) {
		BackResult result = mobileRcptService.getWxPayParams(tradeNo, userid);
		return result;
	}

	/**
	 * 行程提交
	 * 
	 * @return
	 * @throws ParseException
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "tripcounselor", method = RequestMethod.POST)
	@ResponseBody
	@Transactional(propagation = Propagation.REQUIRED)
	public Map<String, Object> tripCounselor(CuponsInfo cuponsInfo, TripCounselorInfo info, HttpServletRequest request)
			throws Exception {
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", "");
		String[] code = request.getParameter("cityCode").split(",");
		String[] scenery = request.getParameter("scenery").split(",");
		Date departtime = df.parse(request.getParameter("depart"));// 出发时间
		Date overtime = df.parse(request.getParameter("over"));// 结束时间
		String price = request.getParameter("price");// 价格
		info.setDepartTime(departtime);
		info.setOverTime(overtime);
		info.setPrice(Double.parseDouble(price));
		info.setTripCounselorId(UUID.randomUUID().toString().replace("-", "").toUpperCase());
		info.setCreate_time(new Date());
		info.setPayState("0");// 支付状态设置0 未支付

		// 价格验证
		MealsInfo mealInfo = tripCounselorService.getMeals();
		double perprice = 0;
		double permoney = 0;
		long to = overtime.getTime();
		long from = departtime.getTime();
		perprice = (to - from) / (1000 * 60 * 60 * 24) + 1;

		if (cuponsInfo.getCuponsId() != null && cuponsInfo.getCuponsId().length() > 0) {
			permoney = info.getPrice() + Long.parseLong(cuponsInfo.getMoney());
		} else {
			permoney = info.getPrice();
		}
		if (info.getSetmeal().equals("0")) {
			if (perprice * Integer.parseInt(mealInfo.getBase()) != permoney) {
				map.put("code", "-1");
				map.put("message", "提交失败");
				return map;
			}
		} else {
			if (perprice * Integer.parseInt(mealInfo.getAdvance()) != permoney) {
				map.put("code", "-1");
				map.put("message", "提交失败");
				return map;
			}
		}
		// 优惠券验证
		if (cuponsInfo.getCuponsId() != null && cuponsInfo.getCuponsId().length() > 0) {
			CuponsInfo a = tCuponsService.getCuponsByRecordId(cuponsInfo.getCuponsId());
			if (permoney < Double.parseDouble(a.getMinPrice())) {
				map.put("code", "-1");
				map.put("message", "提交失败");
				return map;
			}
		}
		TOrders orders = new TOrders();
		if (cuponsInfo.getCuponsId() != null && cuponsInfo.getCuponsId().length() > 0) {
			orders.setUseCupons("1");
		} else {
			orders.setUseCupons("0");
		}
		orders.setTripId(info.getTripCounselorId());
		orders.setRealscheid("0");
		orders.setOrdertype("9");
		orders.setPurchasenum("0");
		orders.setOrderstatus("1");
		orders.setIscheck("Y");
		orders.setOrderuserid(info.getUserId());
		orders.setCreateDate(new Date());
		orders.setDepartdate(departtime);
		String text = "";
		if (info.getSetmeal().equals("0")) {
			text = info.getDepartCity() + "-" + "基础套餐";
		} else {
			text = info.getDepartCity() + "-" + "高级套餐";
		}
		orders.setOrdername(text);
		orders.setDelFlag("0");
		orders.setBoardaddr(info.getDepartCity());
		orders.setDueamount(price);
		orders.setContacts(info.getLinkMan());
		orders.setPayertel(info.getPhone());
		orders.setIsBalance("0");
		tOrdersService.save(orders);// 存入order表
		TOrders order = tOrdersService.getOrderByTripId(info.getTripCounselorId());
		orderService.insertTmpOrders(order.getOrderid());
		if (cuponsInfo.getCuponsId() != null && cuponsInfo.getCuponsId().length() > 0) {
			cuponsInfo.setOrderId(order.getOrderid());
			cuponsInfo.setUseTime(new Date());
			tCuponsService.useCupon(cuponsInfo);
		}

		// 插入目的地信息
		DestinationInfo area = new DestinationInfo();
		for (int t = 0; t < code.length; t++) {
			area.setTripId(info.getTripCounselorId());
			area.setDestinationId(UUID.randomUUID().toString().replace("-", "").toUpperCase());
			area.setDestination(code[t]);
			area.setCreate_time(new Date());
			int j = destinationService.insertDestination(area);
			if (j <= 0) {
				map.put("code", "-1");
				map.put("message", "提交失败");
				return map;
			}
		}

		// 插入景点信息
		CitySceneryInfo place = new CitySceneryInfo();
		for (int t = 0; t < scenery.length; t++) {
			place.setTripId(info.getTripCounselorId());
			place.setCitySceneryId(UUID.randomUUID().toString().replace("-", "").toUpperCase());
			place.setScenery(scenery[t]);
			place.setCreate_time(new Date());
			int z = citySceneryService.insertCityScenery(place);
			if (z <= 0) {
				map.put("code", "-1");
				map.put("message", "提交失败");
				return map;
			}
		}

		int i = tripCounselorService.insertTrip(info);
		if (i <= 0) {
			map.put("code", "-1");
			map.put("message", "提交失败");
			return map;
		}
		Map<String, Object> list = new HashMap<String, Object>();
		list.put("orderId", order.getOrderid());
		list.put("orderName", text);
		map.put("data", list);
		return map;
	}

	/**
	 * 游玩主题
	 * 
	 * @return
	 */
	@RequestMapping(value = "triptheme", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> tripTheme(HttpServletRequest request) throws Exception {
		List<ThemeInfo> themeInfo = themeService.getThemeList();
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", themeInfo);
		return map;
	}

	/**
	 * 酒店标准
	 * 
	 * @return
	 */
	@RequestMapping(value = "hotelstandard", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> hotelStandard(HttpServletRequest request) throws Exception {
		List<HotelStandardInfo> hotelStandard = hotelStandardService.getHotelStandard();
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", hotelStandard);
		return map;
	}

	/**
	 * 交通方式
	 * 
	 * @return
	 */
	@RequestMapping(value = "transportway", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> transportWay(HttpServletRequest request) throws Exception {
		List<TransportWayInfo> transportWay = transportWayService.getTransportWayList();
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", transportWay);
		return map;
	}

	/**
	 * 住宿标准
	 * 
	 * @return
	 */
	@RequestMapping(value = "staystandard", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> stayStandard(HttpServletRequest request) throws Exception {
		List<StayStandardInfo> stayStandard = stayStandardService.getStayStandardList();
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", stayStandard);
		return map;
	}

	/**
	 * 代订交通票
	 * 
	 * @return
	 */
	@RequestMapping(value = "traffic", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> traffic(HttpServletRequest request) throws Exception {
		List<TrafficInfo> traffic = trafficService.getTrafficList();
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", traffic);
		return map;
	}

	/**
	 * 必游景点
	 * 
	 * @return
	 */
	@RequestMapping(value = "cityscenery", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> cityScenery(HttpServletRequest request) throws Exception {
		String[] code = request.getParameter("citycode").split(",");
		List<CitySceneryInfo> scenery = new ArrayList<CitySceneryInfo>();
		CitySceneryInfo a = new CitySceneryInfo();
		a.setSceneryName("不限");
		a.setCitySceneryId("0");
		a.setCityCode("9999999");// 没有实际意义
		scenery.add(a);
		scenery.addAll(citySceneryService.getCitySceneryList(code));
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", scenery);
		return map;
	}

	/**
	 * 必游景点搜索
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "scenerysearch", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> scenerySearch(String sceneryName, HttpServletRequest request) throws Exception {
		String[] code = request.getParameter("citycode").split(",");
		List<CitySceneryInfo> scenery = citySceneryService.getScenerySearch(code, sceneryName);
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", scenery);
		return map;
	}

	/**
	 * 获取行程顾问套餐信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "meals", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> meals(HttpServletRequest request) throws Exception {
		MealsInfo info = tripCounselorService.getMeals();
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", info);
		return map;
	}

	/**
	 * 获取个人行程顾问记录
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 * @throws ParseException
	 */
	@RequestMapping(value = "triprecord", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> tripRecord(String userId, HttpServletRequest request) throws Exception, ParseException {

		// 根据用户id找到用户所有行程记录
		List<TripCounselorInfo> info = tripCounselorService.getTripCounselorList(userId);

		for (int i = 0; i < info.size(); i++) {

			String tripId = info.get(i).getTripCounselorId();// 根据tripId去查找该次行程的目的地和必游景点

			String[] name = destinationService.getDestinationList(tripId);
			for (int j = 0; j < name.length; j++) {
				DestinationInfo d = new DestinationInfo();
				d.setDestination(name[j]);
				info.get(i).getDestination().add(d);
			}
			String[] name2 = citySceneryService.getCitySceneryListByTripId(tripId);
			for (int j = 0; j < name2.length; j++) {
				CitySceneryInfo c = new CitySceneryInfo();
				c.setSceneryName(name2[j]);
				info.get(i).getCityScenery().add(c);
			}
		}
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", info);
		return map;
	}

	/**
	 * 提现信息填写
	 **/
	@RequestMapping(value = "extractinsert", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> extractInsert(ExtractInfo info, HttpServletRequest request) throws Exception {

		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", "");
		Calendar time = Calendar.getInstance();
		time = Calendar.getInstance();
        time.set(Calendar.DAY_OF_MONTH, 9);  
        long now =(new Date()).getTime();
		if(now<time.getTimeInMillis()){ 
			map.put("code", "400");
			map.put("message", "请于每月9日之后提现");
			return map;
		}
		ExtractInfo t = extractService.getExtractById(info.getUserId());
		// 如果之前没有就插入新记录
		if (t == null) {
			if (ValidateTool.checkSFZ(info.getIdentification()) == false) {
				map.put("code", "-2");
				map.put("message", "身份证号错误");
				return map;
			}
			info.setCreate_time(new Date());

			int i = extractService.extractInsert(info);
			if (i <= 0) {
				map.put("code", "-1");
				map.put("message", "提交失败");
			}
		} else {
			// 若有则更新记录
			if (ValidateTool.checkSFZ(info.getIdentification()) == false) {
				map.put("code", "-2");
				map.put("message", "身份证号错误");
				return map;
			}

			int i = extractService.updateExtract(info);

			if (i <= 0) {
				map.put("Code", "-1");
				map.put("Message", "提交失败");
			}
		}
		return map;
	}

	/**
	 * 获取用户提现信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "extractinfo", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> extractInfo(String userId, HttpServletRequest request) throws Exception {
		ExtractInfo info = extractService.getExtractById(userId);
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", info);
		return map;
	}

	/**
	 * 获取用户提现记录列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "withdrawrecord", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> withdrawRecord(String userId, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<DistributionInfo> info = distributionService.getByUserId(userId);
		if (info == null || info.size() < 1) {
			map.put("code", "400");
			map.put("message", "暂无提现记录");
			return map;
		}
		Page<DistributionInfo> page = new Page<DistributionInfo>(request, response);
		page.setPageSize(Integer.parseInt(request.getParameter("pageSize")));
		page.setPageNo(Integer.parseInt(request.getParameter("pageNo")));
		page.setList(info);

		Map<String, Object> form = new HashMap<String, Object>();
		form.put("totalCount", page.getCount());
		form.put("info", info);
		map = new HashMap<String, Object>();
		map.put("code", "200");
		map.put("message", "");
		map.put("data", form);
		return map;
	}

	/**
	 * 提交用户提现申请
	 * 
	 * @return
	 */
	@RequestMapping(value = "importwithdraw", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> importWithdraw(DistributionInfo distributionInfo, HttpServletRequest request)
			throws Exception {
		int i = distributionService.insertWhitdraw(distributionInfo);
		map = new HashMap<String, Object>();
		if (i > 0) {
			map.put("code", "200");
			map.put("message", "");
			map.put("data", "");
		} else {
			map.put("code", "-1");
			map.put("message", "提交失败");

		}
		return map;
	}

	/**
	 * 获取计佣订单列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "orderlist", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> orderList(String userId, HttpServletRequest request) throws Exception {
		List<OrderInfo> info = orderService.getOrderList(userId);
		map = new HashMap<String, Object>();
		if (info == null || info.size() < 1) {
			map.put("code", "400");
			map.put("message", "暂无记录");
			return map;
		}
		map.put("code", "200");
		map.put("message", "");
		map.put("data", info);
		return map;
	}

	/**
	 * 获取计佣订单明细列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "withdraw", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> withdraw(String userId, HttpServletRequest request) throws Exception {
		List<OrderInfo> info = orderService.getNoBalanceList(userId);
		long time = ValidateTool.getMonthFirstDay();// 获取本月的第一天
		double money = 0;
		for (int i = 0; i < info.size(); i++) {
			if (info.get(i).getCreateDate().getTime() >= time) {// 如果计佣订单的完单时间大于本月第一天则不计算该记录
				info.remove(i);
				i--;
			} else {
				money += Double.parseDouble(info.get(i).getDueAmount());
			}
		}

		DecimalFormat df2 = new DecimalFormat("#.00");// 保留两位小数
		map = new HashMap<String, Object>();
		Map<String, Object> list = new HashMap<String, Object>();
		if (info == null || info.size() < 1) {
			list.put("money", "0");
			map.put("code", "200");
			map.put("message", "暂无提现记录");
			map.put("data", list);
			return map;
		}
		float rate = Float.parseFloat(tDistributionService.getRate());
		list.put("info", info);
		list.put("money", money == 0 ? '0' : df2.format(money * rate));
		map.put("code", "200");
		map.put("message", "");
		map.put("data", list);
		return map;
	}

	/**
	 * 获取我的优惠券
	 * 
	 * @return
	 */
	@RequestMapping(value = "mycupons", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> myCupons(String userId, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<CuponsInfo> info = tCuponsService.getMyCupons(userId);
		Page<CuponsInfo> page = new Page<CuponsInfo>(request, response);
		page.setPageSize(Integer.parseInt(request.getParameter("pageSize")));
		page.setPageNo(Integer.parseInt(request.getParameter("pageNo")));
		page.setList(info);
		Map<String, Object> form = new HashMap<String, Object>();
		form.put("totalCount", page.getCount());
		form.put("info", info);
		map = new HashMap<String, Object>();
		if (info == null || info.size() < 1) {
			map.put("code", "400");
			map.put("message", "暂无记录");
			return map;
		}
		map.put("code", "200");
		map.put("message", "");
		map.put("data", form);
		return map;
	}

	/**
	 * 分发注册红包
	 * 
	 * @return
	 */
	@RequestMapping(value = "registcupons", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> registCupons(String userId, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		CuponsInfo info = tCuponsService.getCuponsById("e3c7b1b6a6044d0994d3aeb0e3d55088");
		map = new HashMap<String, Object>();
		if (Integer.parseInt(info.getLimit()) > 0) {
			List<CuponsInfo> list = tCuponsService.getMyCupons(userId);
			for (int i = 0; i < list.size(); i++) {
				if (!list.get(i).getCuponsId().equals("e3c7b1b6a6044d0994d3aeb0e3d55088")) {
					list.remove(i);
					i--;
				}
			}
			if (list.size() >= Integer.parseInt(info.getLimit())) {
				map.put("code", "400");
				map.put("message", "您已不能领取该优惠券");
				map.put("data", "");
				return map;
			}
		}

		int i = tCuponsService.registCupons(userId);
		Map<String, Object> a = new HashMap<String, Object>();
		String url = "https://www.xiakeyueche.com/youhuiquan.jsp?";
		if (i > 0) {
			url = url + "name=" + info.getName() + "&price=" + info.getPrice() + "&minPrice=" + info.getMinPrice()
					+ "&timeBegin=" + df.format(info.getTimeBegin()) + "&timeOver=" + df.format(info.getTimeOver())
					+ "&dateLimit=" + info.getDateLimit() + "&dateType=" + info.getDateType();
			a.put("info", info);
			a.put("url", url);
			map.put("code", "200");
			map.put("message", "");
			map.put("data", a);
		} else if (i == -2) {
			map.put("code", "-2");
			map.put("message", "优惠券已发完");
			map.put("data", "");
		} else {
			map.put("code", "-1");
			map.put("message", "领取失败");
			map.put("data", "");
		}
		return map;
	}

	/**
	 * 获取我的可使用优惠券
	 * 
	 * @return
	 */
	@RequestMapping(value = "canusecupons", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> canUseCupons(String userId, String nowPrice, HttpServletRequest request)
			throws Exception {
		List<CuponsInfo> info = tCuponsService.CanUseCupons(nowPrice, userId);
		for(int i=0;i<info.size();i++){
			if(info.get(i).getCuponsId().equals("4EA0791D3EA945C190FACE91376059F2")){
				info.remove(i);
				i--;
			}
		}
		map = new HashMap<String, Object>();
		if (info == null || info.size() < 1) {
			map.put("code", "0");
			map.put("message", "没有数据");
		} else {
			map.put("code", "200");
			map.put("message", "");
			map.put("data", info);
		}
		return map;
	}

	/**
	 * 行程规划
	 * 
	 * @return
	 */
	@RequestMapping(value = "preview", method = RequestMethod.GET)
	public String preview(String tripCounselorId, HttpServletRequest request, Model model) throws Exception {
		List<TripCounselorInfo> list = tripCounselorService.getTripPreviewList(tripCounselorId);
		if (list.get(0).getIsDisable().equals("1")) {
			model.addAttribute("data", list);
			return "/modules/base/xcyl";
		} else {
			model.addAttribute("data", "暂无数据");
			return "/modules/base/xcyl";
		}
	}
	/**
	 * 一元包车活动 活动信息
	 */
	@RequestMapping(value = "activityInfo")
	public String activityInfo( String userid,HttpServletRequest request, Model model) throws Exception {
		ActivityInfo activity = tActivityService.get("123");
		model.addAttribute("userid", userid);
		if (activity!=null&&activity.getIsUse().equals("1")) {
			model.addAttribute("data", activity);
			return "/modules/activity/onecarSubmit";
		} else {
			model.addAttribute("data", "暂无数据");
			return "/modules/activity/onecarSubmit";
		}
	}
	
	/**
	 * 一元包车活动 提交
	 */
	@RequestMapping(value = "activitySubmit" )
	public void activitySubmit( TOrders orders,HttpServletRequest request, Model model,HttpServletResponse response) throws Exception {
		Map<String, Object> map=new HashMap<String, Object>();
		if(orders.getOrderuserid()==null||orders.getOrderuserid().length()==0){
			map.put("result", false);
			map.put("msg", "请先登录");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
			return;
		}
		TRentproduct tRentproduct = new TRentproduct();
		//手机端传入日期格式 2000-01-01 06:00
		String fromdateStr = request.getParameter("fromdateStr");
		String[] arr = fromdateStr.split("\\s");//按空格切割
		tRentproduct.setFromdateStr(arr[0]);
		tRentproduct.setTime(arr[1]);
		tRentproduct.setDepartdate(DateUtils.parseDate(fromdateStr));
		tRentproduct.setSysDate(new Date());
		String warningFor2Hours = tRentproduct.handle2HoursWarning();
		if (warningFor2Hours != null) {
			map.put("result", false);
			map.put("msg", "距离发车时间不足2小时，请重新选择发车时间");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
			return;
		}
		//处理时间
		orders.setDepartdateStr(fromdateStr);
		// 消息集合
		List<String> messages = Lists.newArrayList(); // 消息
		ActivityInfo activity=tActivityService.get(orders.getActivityId());
		float totalPrice=Float.parseFloat(request.getParameter("totalPrice"));
		//价格验证
		if((Float.parseFloat(orders.getPurchasenum())*Float.parseFloat(activity.getTicket())+Float.parseFloat(activity.getCarPrice()))==totalPrice){
			orders.setDueamount(request.getParameter("totalPrice"));
		}else{
			map.put("result", false);
			map.put("msg", "提交失败");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
			return;
		}
		String school =request.getParameter("school");
		String stunum =request.getParameter("stunum");
		orders.setRemarks(school+"  "+stunum);
		if (messages.isEmpty()) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
			orders.setDepartdate(sdf.parse(fromdateStr));//Fri Aug 25 06:00:00 CST 2017
			try {
				orders.setBookingdays(1);
				orders.setUseCupons("0");
				orders.setRealscheid("0");
				orders.setOrdertype("5");
				orders.setOrderstatus("1");
				orders.setIscheck("Y");
				tOrdersService.save(orders);// 存入order表
				int i=orderService.insertTmpOrders(orders.getOrderid());
				if (i>0) { // 如果成功生成订单，跳到支付方式选择页面
					map.put("result", true);
					map.put("orderid", orders.getOrderid());
					map.put("ordername", orders.getOrdername());
					map.put("price", orders.getDueamount());
					JSONObject data = JsonUtils.mapToJson(map);
					response.getWriter().print(data);
					return;
				}
			} catch (Exception e) {
				messages.add(e.getMessage());
			}
		}
		
		map.put("result", false);
		map.put("msg", "提交失败");
		JSONObject data = JsonUtils.mapToJson(map);
		response.getWriter().print(data);
		return;
	}
	/**
	 * 获取AA拼车第2次我的可使用优惠券
	 * 
	 * @return
	 */
	@RequestMapping(value = "canUseAACupons", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> canUseAACupons(String userId, String nowPrice, HttpServletRequest request)
			throws Exception {
		List<CuponsInfo> info = tCuponsService.CanUseCupons(nowPrice, userId);
		for(int i=0;i<info.size();i++){
			if(!info.get(i).getCuponsId().equals("4EA0791D3EA945C190FACE91376059F2")){
				info.remove(i);
				i--;
			}
		}
		map = new HashMap<String, Object>();
		if (info == null || info.size() < 1) {
			map.put("code", "0");
			map.put("message", "没有数据");
		} else {
			map.put("code", "200");
			map.put("message", "");
			map.put("data", info);
		}
		return map;
	}
	
	/**
	 * 分发拼车优惠券
	 * 
	 * @return
	 */
	@RequestMapping(value = "aaCarCupons", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> aaCarCupons(String userId, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		CuponsInfo info = tCuponsService.getCuponsById("4EA0791D3EA945C190FACE91376059F2");
		map = new HashMap<String, Object>();
		if (Integer.parseInt(info.getLimit()) > 0) {
			List<CuponsInfo> list = tCuponsService.getMyCupons(userId);
			for (int i = 0; i < list.size(); i++) {
				if (!list.get(i).getCuponsId().equals("4EA0791D3EA945C190FACE91376059F2")) {
					list.remove(i);
					i--;
				}
			}
			if (list.size() >= Integer.parseInt(info.getLimit())) {
				map.put("code", "400");
				map.put("message", "您已不能领取该优惠券");
				map.put("data", "");
				return map;
			}
		}

		int i = tCuponsService.aaCarCupons(userId);
		Map<String, Object> a = new HashMap<String, Object>();
		if (i > 0) {
			a.put("info", info);
			map.put("code", "200");
			map.put("message", "");
			map.put("data", a);
		} else if (i == -2) {
			map.put("code", "-2");
			map.put("message", "优惠券已发完");
			map.put("data", "");
		} else {
			map.put("code", "-1");
			map.put("message", "领取失败");
			map.put("data", "");
		}
		return map;
	}
	
	/**
	 * 分发9折优惠券
	 * 
	 * @return
	 */
	@RequestMapping(value = "nineCupons", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> nineCupons(String userId, HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		CuponsInfo info = tCuponsService.getCuponsById("B1870DFCFEB74298A0833B9C6A69EDF5");
		map = new HashMap<String, Object>();
		if (Integer.parseInt(info.getLimit()) > 0) {
			List<CuponsInfo> list = tCuponsService.getMyCupons(userId);
			for (int i = 0; i < list.size(); i++) {
				if (!list.get(i).getCuponsId().equals("B1870DFCFEB74298A0833B9C6A69EDF5")) {
					list.remove(i);
					i--;
				}
			}
			if (list.size() >= Integer.parseInt(info.getLimit())) {
				map.put("code", "400");
				map.put("message", "您已不能领取该优惠券");
				map.put("data", "");
				return map;
			}
		}

		int i = tCuponsService.nineCupons(userId);
		Map<String, Object> a = new HashMap<String, Object>();
		if (i > 0) {
			a.put("info", info);
			map.put("code", "200");
			map.put("message", "");
			map.put("data", a);
		} else if (i == -2) {
			map.put("code", "-2");
			map.put("message", "优惠券已发完");
			map.put("data", "");
		} else {
			map.put("code", "-1");
			map.put("message", "领取失败");
			map.put("data", "");
		}
		return map;
	}
	
	/**
	 * 分发9折优惠券
	 * 网页专用
	 * @return
	 */
	@RequestMapping(value = "nineCuponsWeb", method = RequestMethod.POST)
	@ResponseBody
	public void nineCuponsWeb(String tel,HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Map<String, Object> map=new HashMap<String, Object>();
		String regExp = "^[1][3,4,5,7,8][0-9]{9}$";  
		Pattern p = Pattern.compile(regExp); 
		Matcher m = p.matcher(tel);
		if(tel==null||tel.trim().length()==0){
			map.put("result", false);
			map.put("msg", "请输入手机号");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
			return;
		}else if(tel!=null&&!m.matches()){
			map.put("result", false);
			map.put("msg", "请输入正确的手机号");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
			return;
		}
		User user = new User();
		user.setLoginName(tel);
		List<User> userList = systemService.findList(user);
		if(userList!=null && !userList.isEmpty()){
			user = userList.get(0);
		} else {
			map.put("result", false);
			map.put("down", true);
			map.put("msg", "未注册，请先注册");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
			return;
		}
		
		CuponsInfo info = tCuponsService.getCuponsById("B1870DFCFEB74298A0833B9C6A69EDF5");
		map = new HashMap<String, Object>();
		if (Integer.parseInt(info.getLimit()) > 0) {
			List<CuponsInfo> list = tCuponsService.getMyCupons(user.getId());
			for (int i = 0; i < list.size(); i++) {
				if (!list.get(i).getCuponsId().equals("B1870DFCFEB74298A0833B9C6A69EDF5")) {
					list.remove(i);
					i--;
				}
			}
			if (list.size() >= Integer.parseInt(info.getLimit())) {
				map.put("result", false);
				map.put("msg", "您已不能领取该优惠券");
				JSONObject data = JsonUtils.mapToJson(map);
				response.getWriter().print(data);
				return;
			}
		}
		int i = tCuponsService.nineCupons(user.getId());
		if (i > 0) {
			map.put("result", true);
			map.put("msg", "");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
		} else if (i == -2) {
			map.put("result", false);
			map.put("msg", "优惠券已发完");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
		} else {
			map.put("result", false);
			map.put("msg", "领取失败");
			JSONObject data = JsonUtils.mapToJson(map);
			response.getWriter().print(data);
		}
		return;
	}
	
}
